﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AgileNYCWebService.Manager.Data.Table;
using System.Web.Script.Serialization;
using Newtonsoft.Json;

namespace AgileNYCWebService
{
	public partial class upload : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected void btnUpload_OnClick(object sender, EventArgs e)
		{
			//string requestUrl = @"http://localhost:19368/AgileUsers.svc/UploadImage?userToken=a6vRPEPXwUOR1iWQle27Cg==";
            string requestUrl = @"http://localhost:19368/AgileUsers.svc/UploadPhoto/qEikcWe8L0KMft6BnbA4w==";
			//string requestUrl = @"http://localhost:19368/AgileUsers.svc?public_id=1";
			//file to upload make sure it exist
            string filename = @"C:\Users\Hikmat\Desktop\rNUo8Tz10eA.jpg-600x.jpg";

			HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
			request.Method = "POST";
			//request.ContentType = "binary/octet-stream";
			//request.ContentType = "application/json; charset=utf-8";
			request.ContentType = "binary/octet-stream";
			//request.ContentType = "text/plain";
			byte[] fileToSend = File.ReadAllBytes(filename);
			//request.ContentLength = fileToSend.Length;

			using (Stream requestStream = request.GetRequestStream())
			{
				// Send the file as body request. 

				requestStream.Write(fileToSend, 0, fileToSend.Length);
				requestStream.Close();
			}

			using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
			{
				System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream());
				String s = sr.ReadToEnd().Trim();
				string result = s;
			}
		}
	}
}